package com.example.demo.entity;

import com.example.demo.enums.CodeEnum;
import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseInfo<T> implements Serializable {
    private Integer code;
    private T data;
    private String message;
    private Boolean success;

    private static final long serialVersionUID = 1L;

    public ResponseInfo() {

    }

    public ResponseInfo(Integer code, String message, T data, Boolean success) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.success = success;
    }

    public static <T> ResponseInfo<T> successInfo(T data) {
        return new ResponseInfo<T>(CodeEnum.RESPONSE_SUCCESS.getCode(), CodeEnum.RESPONSE_SUCCESS.getMessage(), data, true);
    }

    public static <T> ResponseInfo<T> errorInfo(String message) {
        return new ResponseInfo<T>(520, message, null, false);
    }
    public static <T> ResponseInfo<T> errorInfo(int code,String message,T data) {
        return new ResponseInfo<T>(code, message, data, false);
    }


}
